﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Collections;

namespace PROJECT_BOMBER.BLL
{
    public class LevelBloc : IEnumerable, ICloneable
    {

        private Game game;

        public Game Game
        {
            get { return game; }
            set { game = value; }
        }

        int _nextlevel;

        public int Nextlevel
        {
            get { return _nextlevel; }
            set { _nextlevel = value; }
        }

        #region Contructeur

        public LevelBloc(int nexlevel, Game game)
        {
            Nextlevel = nexlevel;
        }

        #endregion

        public List<ElementPhysique> listElement = new List<ElementPhysique>();



        #region Base

        AnimationSprite _base;
        public AnimationSprite Base()
        {
            return _base;
        }

        public void Base(AnimationSprite sprite)
        {
            _base = sprite;
        }

        public void Base(AnimationDefinition anim, Game game)
        {
            _base = new AnimationSprite(game, anim);
            //Base().Position = new Point((int)Element.Positionbase.X, (int)Element.Positionbase.Y);
        }
        #endregion

        #region Background

        AnimationSprite _background;
        public AnimationSprite Background()
        {
            return _background;
        }

        public void Background(AnimationSprite sprite)
        {
            _background = sprite;
        }

        public void Background(AnimationDefinition anim, Game game)
        {
            _background = new AnimationSprite(game, anim);
            //Base().Position = new Point((int)Element.Positionbase.X, (int)Element.Positionbase.Y);
        }
        #endregion

        #region Foreground

        AnimationSprite _foreground;
        public AnimationSprite Foreground()
        {
            return _foreground;
        }

        public void Foreground(AnimationSprite sprite)
        {
            _foreground = sprite;
        }

        public void Foreground(AnimationDefinition anim, Game game)
        {
            _foreground = new AnimationSprite(game, anim);
            //Base().Position = new Point((int)Element.Positionbase.X, (int)Element.Positionbase.Y);
        }


        #endregion

        public IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public object Clone()
        {
            LevelBloc lvl = new LevelBloc(this.Nextlevel, this.Game);
            lvl.Background((AnimationSprite)this.Background().Clone());
            lvl.Base((AnimationSprite)this.Base().Clone());
            lvl.Foreground((AnimationSprite)this.Foreground().Clone());

            foreach (var item in listElement)
            {
                if (item.GetType() == typeof(Lava))
                {
                    Lava lava = (Lava)((Lava)item).Clone();

                    lvl.listElement.Add((ElementPhysique)(lava));
                }
                else  if (item.GetType() == typeof(Win))
                {
                    Win win = (Win)((Win)item).Clone();

                    lvl.listElement.Add((ElementPhysique)(win));
                }
                else if (item.GetType() == typeof(Trampolline))
                {
                    Trampolline tramp = (Trampolline)((Trampolline)item).Clone();

                    lvl.listElement.Add((ElementPhysique)(tramp));
                }
                else if (item.GetType() == typeof(Piece))
                {
                    Piece piece = (Piece)((Piece)item).Clone();

                    lvl.listElement.Add((ElementPhysique)(piece));
                }
            }

            return lvl;

        }


    }
}
